import http from "@/http";

export const userListApi = (
  params: IUserListParams
): RES<ITableResult<IUserModel>> => http.get("/admin/list", { params });

export const switchUserStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/admin/updateStatus/${id}?status=${status}`);

export const addUserApi = (params: IUserModel): RES<IUserModel> =>
  http.post("/admin/register", params);

export const getUserById = (id: number): RES<IUserModel> =>
  http.get(`/admin/${id}`);

export const updateUser = (params: IUserModel): RES<number> =>
  http.post(`/admin/update/${params.id}`, params);

export const getRoleListApi = (): RES<IRoleModel[]> =>
  http.get("/role/listAll");

export const getRolesByUserIdApi = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);

export const updateUserRolesApi = (id: number, ids: number[]): RES<number> =>
  http.post(`/admin/role/update?adminId=${id}&roleIds=${ids.join(",")}`);

// 角色列表
export const roleListApi = (
  params: IUserListParams
): RES<ITableResult<IRoleModel>> => http.get("/role/list", { params });
export const roleCreateApi = (params: RoleCreate): RES<number> =>
  http.post("/role/create", params);
export const roleUpdateApi = (params: IRoleModel): RES<number> =>
  http.post(`/role/update/${params.id}`, params);
export const switchRoleStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/role/updateStatus/${id}?status=${status}`);
// export const treeListApi = (): RES<IRoleModel[]> => http.get("/menu/treeList");

// 分配资源
export const getRourceListAllApi = (roleId: number): RES<IResourceModel[]> =>
  http.get(`/role/listResource/${roleId}`);
export const resourceListAllApi = (): RES<IResourceModel[]> =>
  http.get(`/resource/listAll`);
export const resourceCategoryListAll = (): RES<IResourceCategoryModel[]> =>
  http.get("/resourceCategory/listAll");

export const allocResourceApi = (paramas: allocResourcePramas) =>
  http.post(
    `/role/allocResource?roleId=${
      paramas.roleId
    }&resourceIds=${paramas.resourceIds.join(",")}`
  );
// 分配菜单
export const treeListApi = (): RES<ItreeMenu[]> => http.get("/menu/treeList");
export const roleListMenuApi = (roleId: number): RES<RoleListMenu[]> =>
  http.get(`/role/listMenu/${roleId}`);
export const allocMenuApi = (paramas: allocResourcePramas) =>
  http.post(
    `/role/allocMenu?roleId=${
      paramas.roleId
    }&menuIds=${paramas.resourceIds.join(",")}`
  );
// 资源列表
export const getResourceListApi = (
  params: any
): RES<ITableResult<ResourceList>> => http.get("/resource/list", { params });
// 菜单列表
export const getMenuListApi = (params: any): RES<ITableResult<GetMenuList>> =>
  http.get(`/menu/list/${params.id}`, params);
export const MenuUpdateHiddenApi = (id: number, status: number): RES<number> =>
  http.post(`/menu/updateHidden/${id}?hidden=${status}`);
